//
//  CompanyTopView.swift
//  AirlineReservation
//
//  Created by Kevin on 2020/2/16.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class CompanyTopView: UIView {
    
    // 常量
    private let titles = ["抬头","税号"]
    private let placeholders = ["必填，公司名称","必填，纳税人识别号"]
    // 存储
    public var titlesViews = [UILabel]()
    public var holderViews = [TextFieldOffsetPlaceHolder]()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        init_views()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        (0..<titles.count).forEach { (i) in
            let labelY = MARGIN + CGFloat(i) * MARGIN70
            // 标题
            let label = titlesViews[i]
            label.text = titles[i]
            label.textColor = COLOR_NICE
            label.font = UIFont.systemFont(ofSize: 15)
            label.frame = CGRect(x: MARGIN, y: labelY, width: MARGIN * 4.8, height: MARGIN30)
            addSubview(label)
            // 输入
            let input = holderViews[i]
            input.frame = CGRect(x: MARGIN, y: labelY, width: SCREEN_WIDTH, height: MARGIN30)
            // 下划线
            let line = UIView()
            line.backgroundColor = COLOR_LINE
            line.frame = CGRect(x: MARGIN, y: input.frame.maxY + MARGIN, width: SCREEN_WIDTH - MARGIN * 2, height: 1)
            
            if i != titles.count - 1 {
                addSubview(line)
            }
        }
    }
}

extension CompanyTopView {
    
    private func init_views() -> Void {
        (0..<titles.count).forEach { (i) in
            let input = TextFieldOffsetPlaceHolder()
            input.placeholder = placeholders[i]
            input.textColor = UIColor.lightGray
            input.font = UIFont.systemFont(ofSize: 13)
            input.setValue(MARGIN * 5, forKey: "paddingLeft")
            holderViews.append(input)
            addSubview(input)
            // 说明
            titlesViews.append(UILabel())
        }
    }
}
